package model

import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.List
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.bindings.PropertyAdapter
import unq.model.Pais
import unq.model.Lugar
import unq.model.Banco
import unq.model.Club
import unq.model.Biblioteca
import unq.model.Embajada
import unq.model.Juego
import unq.model.Lugar
import org.uqbar.commons.utils.Observable
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.widgets.TextBox

@Observable
class PaisEditableWindows extends SimpleWindow<Pais> {

	new(WindowOwner parent, Pais p) {
		super(parent, p)
		title = "Editar Pais"
	}

	override protected createFormPanel(Panel mainPanel) {

		new Panel(mainPanel) => [
			
		new TextBox(it) => [
			bindValueToProperty("nombre")		] 
			crearPanelDeCaracteristicas(it)
			crearPanelDeLugares(it)
			crearPanelDeConexiones(it)


		]
	}


	

	 

	def crearPanelDeConexiones(Panel panel) {
		
				new Panel(panel) => [

			setLayout(new ColumnLayout(2))
			new Label(it) => [text = "Conexiones" fontSize = 13]

			new Button(it) => [
				caption = "Editar Conexiones"

				onClick[| 
					(new EditorWindows<Pais>(this, this.modelObject, "conexiones","agregarConexion","eliminarConexion","posiblesConexiones", Pais))
						   .open()
				]				

			]

			
			new List(it) => [
				val binding = bindItemsToProperty("conexiones")
				binding.setAdapter(new PropertyAdapter(Pais, "nombre"))
				width = 200
		    heigth = 50
			]
			
		]
	
		//		width = 180
		
		}

	def crearPanelDeLugares(Panel panel) {
		new Panel(panel) => [
			setLayout(new ColumnLayout(2))
			new Label(it) => [text = "Lugares De Interes" fontSize = 13]
			new Button(it) => [
				caption = "Editar Lugares"
				onClick[|(new EditorWindows(this, this.modelObject, "lugaresDeInteres","agregarLugar","eliminarLugar","posiblesLugares",Lugar)).open()]
			]
			
			new List(it) => [
				val binding = bindItemsToProperty("lugaresDeInteres")
				binding.setAdapter(new PropertyAdapter(Lugar, "nombre"))
				width = 200
			    heigth = 50
			]
			
		]
	}

	def crearPanelDeCaracteristicas(Panel panel) {
		new Panel(panel) => [
			setLayout(new ColumnLayout(2))
			new Label(it) => [
				text = "Caracteristicas"
				fontSize = 13
			]
			new Button(it) => [caption = "Editar Caracteristicas"
				onClick[ |
					new EditorCaraceristicas<Pais>(this, this.modelObject,"caracteristicas", "elemAgregar", "elemEliminar", "agregarCaracteristica", "eliminarCaracteristica").open
				]]
			new List(it) => [
				bindItemsToProperty("caracteristicas")
				width = 200
				heigth = 50 
			]
		]

	}

	override protected addActions(Panel arg0) {
		new Button(arg0) => [caption = "Aceptar"
				onClick[ |close]]
			
	}

}

